package org.chispa.api.parsers;

import java.util.NoSuchElementException;

import org.chispa.api.util.BadSyntaxException;
import org.chispa.api.util.NoSuitableVisitorException;

class LiteralParserState extends NonInitialParserState {

	protected LiteralParserState(ParserState prev) {
		super(prev);
	}

	@Override
	public ParserState validateState() throws NoSuchElementException, BadSyntaxException, NoSuitableVisitorException {
		if(scan.hasNext())
		{
			String text=scan.next();
			append(text);
			//Is it a closing literal, e.g does it have an 
			//odd number of unescaped double quotes?
			if(isUnclosedLiteral(text))
			{
				return prev.validateState();
			}
			return this.validateState();
		}
		return this;
	}

}
